using System;

namespace SolarWinds.Input
{
    public class InputEvent : EventArgs
    {
        /// <summary>
        /// Time when the event occured
        /// </summary>
        protected TimeSpan mTime;

        /// <summary>
        /// Is the event already consumed (ex. by a call to OnKeyPressed)
        /// </summary>
        protected bool mIsConsumed;

        /// <summary>
        /// Modifiers pressed during the event occured
        /// </summary>
        protected InputModifiers mModifiers;

        #region Properties

        public TimeSpan Time
        {
            get { return mTime; }
        }

        public bool IsConsumed
        {
            get { return mIsConsumed; }
        }

        public InputModifiers Modifiers
        {
            get { return mModifiers; }
        }

        #endregion

        public InputEvent(TimeSpan time, InputModifiers modifiers)
        {
            mTime = time;
            mModifiers = modifiers;
        }

        public void Consume()
        {
            mIsConsumed = true;
        }

        public bool OcurredBetween (TimeSpan start, TimeSpan end)
        {
            return (mTime > start) && (mTime < end);
        }

        public bool IsAltDown()
        {
            return ((int)(mModifiers & InputModifiers.Alt) != 0);
        }

        public bool IsShiftDown()
        {
            return ((int)(mModifiers & InputModifiers.Shift) != 0);
        }

        public bool IsControlDown()
        {
            return ((int)(mModifiers & InputModifiers.Control) != 0);
        }

        public bool IsMetaDown()
        {
            return ((int)(mModifiers & InputModifiers.Meta) != 0);
        }

        public override string ToString()
        {
            return "{Time:" + mTime + " Consumed:" + mIsConsumed + " Modifiers:" + mModifiers + "}";
        }
    }
}